<?php
include('common/autoload.php');

if ($_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest') {
    exit('access error');
}
//权限检测
$member_id = $_SESSION['sid'];

$s = $soap_cli = new SoapClient(null,array(
    "location" => "http://open.12301.cc/openService/pft_insideMX.php",
    "uri" => "www.16u.com?ac_16u=16ucom|pw_16u=c33367701511b4f6020ec61ded352059|auth_16u=true")
);

$request = $_GET = $_POST; //兼容。。。

switch ($request['action']) {
    case 'get_lands':
        include("/var/www/html/new/d/class/Member.php");
        $m = new Member($soap_cli, $member_id);
        $sale = $m->salePros();
        $land = array();
        foreach ($sale as $v) {
            if (!$land[$v['lid']]) {
                $land[$v['lid']] = $v['title'];
            }
        }
        exit(json_encode($land));

    case 'get_distors':
        if($_SESSION['dtype']==0 || $_SESSION['dtype']==1|| $_SESSION['dtype']==6 || $_SESSION['dtype']==7) {
            include 'getDistors.php';
            $member_id = ($_SESSION['dtype']==6 || $_SESSION['dtype']==7) ? $_SESSION['sid']:$_SESSION['memberID'];
            if($_SESSION['dtype']==7){
                $distors = getAll($GLOBALS['le'],$member_id);
            }else{
                $distors = getRetail($GLOBALS['le'],$member_id);
            }
        }
        $distors['1sanke'] = '散客';
        exit(json_encode($distors));

    case 'get_supllys':
        if($_SESSION['dtype']==0 || $_SESSION['dtype']==1) {
            include 'getDistors.php';
            $supplys = getDistors($GLOBALS['le']);
            exit(json_encode($supplys));
        }
        break;

    case 'get_tickets':
        $sql='SELECT id,title FROM uu_jq_ticket WHERE landid='.($request['landid']+0);//
        $GLOBALS['le']->query($sql);
        $tickes = array();
        while($row = $GLOBALS['le']->fetch_assoc()){
            $tickes[] = $row;
        }
        if(count($tickes)){
            echo json_encode(array('status' => 1,'content' => $tickes));
        }else{
            echo json_encode(array('status' => 0));
        }
        exit;

    case 'get_reports':
        $btime = $request['begintime'] ? trim($request['begintime'])
                : date("Y-m-d",strtotime('-7days'));
        $etime = $request['endtime'] ? trim($request['endtime'])
                : date("Y-m-d");
        $btime = strpos($btime,":") !== false ? $btime : $btime." 00:00:00";
        $etime = strpos($etime,":") !== false ? $etime : $etime." 23:59:59";
        $by = $request['by'] ? $request['by'] : "lid";

        $option =array();
        // 景点查询
        if(isset($request['landid']))  {
            $option['lid'] = $request['landid'];
        }
        // 门票查询
        if(isset($request['ticket'])){
            $t = explode("_", $request['ticket']);
            $option['tid'] = $t[0];
        }
        //交易时间类型
        $timeType = 3;
        //分销商ID
        if (isset($request['fid'])) {
            $fid = abs($request['fid']);
            $_GET['aid'] = $_SESSION['sid'];
        }
        if (isset($request['aid'])) {
            $aid = abs($_REQUEST['aid']);
            $_GET['fid'] = $_SESSION['sid'];
        }
        
        include_once 'module/zax/order_report/cetX.php';
        if (count($r)) {
            exit(json_encode(array('status' => 1, 'info' => $r)));
        } else {
            exit(json_encode(array('status' => 0, 'info' => '暂无数据')));
        }
} 